package stream._02;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class App {

	public static void main(String[] args) {
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < 50000000; i++) {
			list.add(i);
		}
		System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "12");

		System.out.println(
				"设置的ForkJoinPool线程数:" + System.getProperty("java.util.concurrent.ForkJoinPool.common.parallelism"));

		Map<Long, Thread> map = new ConcurrentHashMap<Long, Thread>();
		list.parallelStream().forEach((i) -> {
			if (map.get(Thread.currentThread().getId()) == null) {
				map.put(Thread.currentThread().getId(), Thread.currentThread());
			}
		});

		if (map.size() > 13) {
			System.out.println("wtf");
		}

		System.out.println("实际的工作线程数(包括main):" + map.keySet().size());

		for (Long id : map.keySet()) {
			Thread t = map.get(id);
			System.out.println(t.getId() + ":" + t.getName());
		}

	}

}